/**
 * Author: Tang Qiao
 * 2007.5.1
 *
 */
import java.util.*;
class Main
{
	int ncity, nday, i, j, k, n, m;
	int [][] pay;
	int [][] earn;
	int [][] income;
	boolean debug = false;

	void count(){
		int max=0, tmp=0;
		income = new int[m+1][n+1];
		for (j=1; j<=ncity; ++j)
			income[1][j] = -pay[1][j] + earn[1][j];
		for (i=2; i<=nday; ++i)		
			for (j=1; j<=ncity; ++j)
			{
				max = -2000000000;
				for (k=1; k<=ncity; ++k)
				{
					tmp = income[i-1][k] -pay[k][j] + earn[i][j];
					if (max < tmp) max = tmp;
				}
				income[i][j] = max;
			}
		
		//debug
		if (debug)
		{
			System.out.println("debug info:");
			for (i=1; i<=nday; ++i){		
				for (j=1; j<=ncity; ++j)
					System.out.print(income[i][j]+" ");
				System.out.println();
			}
			
		}
		
		
		// output
		max = income[nday][1];
		for (i=1; i<=ncity; ++i)
			if (max < income[nday][i])
				max = income[nday][i];
		System.out.println(max);
	}
	
	void go() throws Exception
	{
		
        Scanner cin = new Scanner(System.in);
        while (true){
        	// input
        	n = ncity = cin.nextInt();
        	m = nday = cin.nextInt();
        	if (n==0 && m==0) break;
        	pay = new int[n+1][n+1];
        	for (i=1; i<=n; ++i)
        		for (j=1; j<=n; ++j)
        			pay[i][j] = cin.nextInt();
        	
        	earn = new int[m+1][n+1];
        	for (i=1; i<=m; ++i)
        		for (j=1; j<=n; ++j)
        			earn[i][j] = cin.nextInt();
        	
        	count();
        }
  
        
	}

    public static void main(String args[]) throws Exception
    {
    	
		new Main().go();
    }

}
